Invoking Value Contract Services
The following actions form example were designed to manage records within a decentralized database.
Both actions require authorization from the user invoking them, ensuring that only authorized entities can modify or delete records.
Action: upsert
The upsert action allows users to create or update a record in the database. If the specified record ID does not exist, upsert will create a new record. If the ID already exists, the action will update the record's data. Parameters
- user (type: name): The authorized account name executing the action.
- id (type: uint64_t): A unique identifier for the record.
- data (type: std::string): The content/data associated with the record ID.
To invoke the upsert action, use the following command:
cline push action contract_name upsert '["user_account", record_id, "record_data"]' -p user_account@active
- contract_name: The blockchain database name where the contract is deployed.
- user_account: The authorized account executing the action.
- record_id: A unique identifier for the record (of type uint64_t).
- record_data: The data string to store in the record.
cline push action examplecontract upsert '["alice", 1001, "Sample data for record 1001"]' -p alice@active
Authorization Check: Ensures that the user calling the action has the necessary permissions.
Entry Search: Searches the table by the primary key (id).
Create or Update: If the entry does not exist, a new record is created. If the entry exists, it updates the data field of the record.
Action: deleteentry
The deleteentry action allows users to delete a specific record by ID, provided the record exists in the database. Parameters
- user (type: name): The authorized account name executing the action.
- id (type: uint64_t): The unique identifier of the record to delete.
To invoke the deleteentry action, use the following command:
cline push action database deleteentry '["user_account", "record_id"]' -p user_account@active
- database: Replace with the blockchain account where the contract is deployed.
- user_account: The authorized account executing the action.
- record_id: The unique identifier for the record (of type uint64_t).
cline push action examplecontract deleteentry '["alice", 1001]' -p alice@active
- Authorization Check: Verifies that the user calling the action has the necessary permissions.
- Entry Validation: Checks if the specified record ID exists in the table.
- Delete Record: If the record exists, it is deleted. If not, an error message is returned.
- Both actions require that the user holds the necessary permissions (active or higher).
- Ensure that the record ID is valid and unique when calling upsert.
- Attempting to delete a non-existent record with deleteentry will trigger an error.